<template>
	<view >
		<vol-form @extraClick="extraClick" :load-key="true" ref="form" :form-options.sync="editFormOptions"
			:formFields.sync="editFormFields">
		</vol-form>

		<view class="btns">
			<view class="btn">
				<u-button type="primary" @click="reset" shape="circle" text="重置表单"></u-button>
			</view>
			<view class="btn">
				<u-button type="success" @click="save" shape="circle" text="保存"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import options from './jxs_registerOptions.js';//引入同目录下的代码生成器生成的js文件
	let _options = options();
	export default {
		data() {
			return {
				opt:_options,
				editFormFields:_options.editFormFields,
				editFormOptions:_options.editFormOptions,
			}
		},
		onLoad() {
			console.log("load..");
		},
		onUnload() {
			console.log("onUnload..");
			uni.navigateTo({
				url: "/pages/mytable/jxs_register/end_back"
			})
		},
		onShow() {
			this.$nextTick(()=>{
				this.$refs.form.reset();
				this.$toast("表单已重置")
			})
			
		},
		onBackPress(options) {//返回return 阻止按钮起效
			console.log("kkkk");
		   /* if (options.from === 'navigateBack') {
		        return false
		    }
		    uni.navigateBack({
		        delta: 100
		    })*/
		    return true
		},
		methods: {
			
			extraClick(item){
				uni.navigateTo({
					url: "/pages/mytable/jxs_register/jxs_register_custom"
				})
			},
			
			save() {
				if (this.$refs.form.validate()) {
					let savedata={//判断前端对象属性为数组 
						mainData:this.editFormFields,
						delKeys: null,
						detailData: null
					}
					var keys=Object.keys(savedata.mainData);//需要把selectList字段类型转换为逗号分割的字符串
					      for (let index = 0; index < keys.length; index++) {
					        const e = keys[index];
							console.log(savedata.mainData[e]);
					        if(Array.isArray(savedata.mainData[e])){//判断savedata.mainData对象中哪些属性为数组的，如果是转为字符串
									console.log(savedata.mainData[e]+"array..........");
					            savedata.mainData[e]=savedata.mainData[e].join(',');//,转换为，分割的字符串，用于volform提交数据
					        }
					      }

					this.http.post("/api/jxs_register/Add", savedata, true).then((s) => {
						this.$toast("保存成功");
						uni.navigateTo({
							url: "/pages/mytable/jxs_register/end_back"
						})
						})
				}
			},
			reset() {
				this.$refs.form.reset();
				this.$toast("表单已重置")
			}
		},
	}
</script>

<style lang="less" scoped>
	.form-test {
		margin-top: -20rpx;
		background: #fbfbfb;
		padding-top: 20rpx;
	}

	.btns {
		display: flex;
		padding: 0rpx 20rpx;

		.btn {
			flex: 1;
			padding: 20rpx;
		}
	}
</style>
